
package logic;

import java.util.ArrayList;

/**
 *
 * @author moustafa
 */
public class CounterBean {
    private String message;
    private ArrayList<CharRecord> counters;

    public CounterBean(){
        message = "";
        counters = new ArrayList<CharRecord>();
    }
    public void setMessage(String message){
        this.message = message;
        for(int i = 0; i < message.length(); i++){
            char character = (message.charAt(i));
            int index = searchCounters(character);
            if(index != -1){
                counters.get(index).incrementCount();
            }else{
                counters.add(new CharRecord(character));
            }
        }
    }
    public String getMessage(){
        return this.message;
    }
    public void setCounters(ArrayList<CharRecord> counters){
        this.counters = counters;
    }
    public ArrayList<CharRecord> getCounters(){
        return this.counters;
    }
    private int searchCounters(char character){
        for(int i = 0; i < this.counters.size(); i++){
            if(this.counters.get(i).character == character){
                return i;
            }
        }
        return -1;
    }
}
